package com.nursing.Dao;

import com.nursing.bean.CarePlan;
import com.nursing.model.dto.CarePlanDto;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CarePlanDao {
    @Select("SELECT ct.*, n.name elderName FROM care_plan ct LEFT JOIN elder n ON ct.elder_id = n.id")
    List<CarePlanDto> getAll();

    @Select("SELECT * FROM care_plan WHERE id = #{id}")
    CarePlan getById(Integer id);

    @Select("SELECT * FROM care_plan WHERE elder_id = #{elderId}")
    List<CarePlan> getByElderId(Integer elderId);

    @Insert("INSERT INTO care_plan (elder_id, plan_details,status) VALUES (#{elderId}, #{planDetails},#{status})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void insert(CarePlan carePlan);

    @Update("UPDATE care_plan SET plan_details = #{planDetails} ,status = #{status} WHERE id = #{id}")
    void update(CarePlan carePlan);

    @Delete("DELETE FROM care_plan WHERE id = #{id}")
    void delete(Integer id);
}